package com.zy.modules.sys.repo;

import com.zy.modules.sys.dao.BDaoImpl;
import com.zy.modules.sys.entity.SysMenuEntity;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>menu</p>
 * Created by zhezhiyong@163.com on 2017/7/25.
 */
@Component
public class MenuDaoImpl extends BDaoImpl<SysMenuEntity> implements MenuDao {
    @Override
    public List<SysMenuEntity> queryUserList(Long userId) {
        String sql = "select distinct m.*,(select p.name from sys_menu p where p.menu_id = m.parent_id) as parentName " +
                "from sys_user_role ur " +
                "LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id " +
                "LEFT JOIN sys_menu m on rm.menu_id = m.menu_id " +
                "where ur.user_id = :userId order by m.order_num asc";
        List<SysMenuEntity> result = (List<SysMenuEntity>) entityManager.createNativeQuery(sql, SysMenuEntity.class).setParameter("userId", userId);
        return result;
    }

    @Override
    public List<SysMenuEntity> findNotButtonList() {
        String sql = "select * from sys_menu where type <> :type order by order_num asc";
        List<SysMenuEntity> result = entityManager.createNativeQuery(sql, SysMenuEntity.class).setParameter("type", 2).getResultList();
        return result;
    }

}
